define(function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        var me = this;
        return {
          urls: {
            flow: backend.workflowService + '/api/biz/',
            start: backend.workflowService + '/api/core/start'
          },
          wfDemo: {
            pkId: '12345678',
            name: '客户-王亚飞',
            id: 'wangyf10',
            flowId: '',
            bizType: ''
          },
          dialogVisible: false,
          queryFields: [
            {placeholder: '业务类型', field: 'bizType', type: 'input'},
            {placeholder: '业务类型描述', field: 'ext', type: 'input'}
          ],
          tableColumns: [
            { label: '业务类型', prop: 'bizType', resizable: true, align: 'center' },
            { label: '业务类型描述', prop: 'ext', resizable: true, align: 'center' },
            { label: '流程编号', prop: 'flowId', resizable: true, align: 'center' },
            { label: '流程名称', prop: 'flowName', resizable: true, align: 'center' },
            { label: '业务页面', prop: 'pageUrl', resizable: true, align: 'center' }
          ],
          queryButtons: [{
            label: '搜索',
            op: 'submit',
            type: 'primary',
            click: function (model, valid) {
              if (valid) {
                var params = {};
                params.bizType = model.bizType;
                if (model.ext != null) {
                  params.ext = '%' + model.ext + '%';
                }
                var param = {
                  condition: JSON.stringify(params)
                };
                me.$refs.refTable.remoteData(param);
              }
            }
          },
          {
            label: '重置',
            op: 'reset'
          }
          ]
        };
      },
      mounted: function () {
        this.reSet();
      },
      methods: {
        selectFn: function () {
          var selections = this.$refs.refTable.selections;
          if (selections.length < 1) {
            this.$message({message: '请选择一条记录', type: 'warning'});
            return;
          }
          this.wfDemo.bizType = selections[0].bizType;
          this.dialogVisible = false;
        },
        openDialog: function () {
          var me = this;
          me.dialogVisible = true;
          me.$nextTick(function () {
            me.$refs.refFormq.$children[0].resetFields();
            me.$refs.refTable.remoteData({});
          });
        },
        reSet: function () {
          var myDate = new Date();
          this.wfDemo.pkId = myDate.getTime(); // 获取日期与时间
        },
        start: function () {
          var _this = this;
          var startdto = {};
          startdto.systemId = 'cmis';
          startdto.orgId = '500';
          startdto.userId = yufp.session.user.loginCode;
          startdto.bizType = _this.wfDemo.bizType;
          startdto.bizId = _this.wfDemo.pkId;
          startdto.bizUserName = _this.wfDemo.name;
          startdto.bizUserId = _this.wfDemo.id;
          startdto.param = {'金额': '10000', 'money': 200};
          startdto.bizParam4 = '111';
          yufp.service.request({
            method: 'POST',
            data: startdto,
            url: _this.urls.start,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data.flowStarterName) {
                  _this.$message({
                    message: response.data.flowStarterName + '成功发起@' + response.data.flowName,
                    type: 'success',
                    duration: 6000
                  });
                }
                _this.reSet();
              } else {
                _this.$message({ duration: 6000,
                  message: '流程发起异常:' + response.message.substring(0, 100),
                  type: 'warning'
                });
                return false;
              }
            }
          });
        }
      }
    });
  };
});
